package com.oraking.android.cmm.view;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.oraking.android.cmm.R;


/**
 * 파일명          : TitleView.java 
 * 작성일          : 2011. 9. 29.
 * 작성자          : <a href='http://oraking.springnote.com/' target='_blank'>Teddy</a>
 * Todo      : 공통 Title
 * 수정내용
 * -------------------------------------------------------------
 *      수정일      |      수정자      |              수정내용              
 * -------------------------------------------------------------
 *              |              |
 */
public class TitleView extends LinearLayout {
	
	private View view;
	private TextView titleTextView;
	private Context mContext;
	
	private Button 	rBtn;				// 오른쪽 버튼
	private Button	lBtn;				// 왼쪽 버튼
	
	public TitleView(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
		mContext = context;
		init();
	}

	public TitleView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		mContext = context;
		init();
	}
	
	/**
	 * @title  : 
	 * @location : com.oraking.android.cmm.view.TitleView.init
	 * @writeDay : 2011. 9. 29. 오후 3:30:03
	 * @Todo  : TitleView 초기화 하는 Method
	 */
	public void init() {
		LayoutInflater li = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		view = li.inflate(R.layout.titleview, this, false);
		addView(view);
		
		titleTextView = (TextView)findViewById(R.id.title_text);
		titleTextView.setTypeface(null, Typeface.BOLD);
		titleTextView.setTypeface(Typeface.SERIF);
		lBtn = (Button)findViewById(R.id.l_btn);
		rBtn = (Button)findViewById(R.id.r_btn);
		
		lBtn.setVisibility(View.GONE);
		rBtn.setVisibility(View.GONE);
		
		rBtn.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View arg0) {
				AlertDialog.Builder alert = new AlertDialog.Builder(getContext());
				alert.setMessage(getResources().getString(R.string.gomain));
				alert.setPositiveButton(R.string.messagebox_ok, new DialogInterface.OnClickListener() {
				    public void onClick( DialogInterface dialog, int which) {
				    	
				    	Intent intent = new Intent();
				    	Activity activity = (Activity)mContext;
				    	activity.setResult(Activity.RESULT_FIRST_USER, intent);
				    	activity.finish();
				    }
				});
				alert.setNegativeButton(getResources().getString(R.string.messagebox_cancel), null);
				alert.show();
			}
		});
	}
	
	/**
	 * @title  : 
	 * @location : com.oraking.android.cmm.view.TitleView.setTitle
	 * @writeDay : 2011. 9. 29. 오후 3:30:03
	 * @Todo  : TitleView 문자열을 설정하는 Method
	 */
	public void setTitle(String title) {
		titleTextView.setText(title);
	}
	
	/**
	 * @title  : 
	 * @location : com.oraking.android.cmm.view.TitleView.setTitle
	 * @writeDay : 2011. 9. 29. 오후 3:30:03
	 * @Todo  : TitleView 문자열과 크기을 설정하는 Method
	 */
	public void setTitle(String title, int size) {
		titleTextView.setText(title);
		titleTextView.setTextSize(size);
	}
	
	/**
	 * @title  : 
	 * @location : com.oraking.android.cmm.view.TitleView.openLeftBtn
	 * @writeDay : 2011. 9. 29. 오후 3:30:03
	 * @Todo  : TitleView 왼쪽 Button 보이도록 설정하는 Method
	 */
	public Button openLeftBtn() {
		lBtn.setVisibility(View.VISIBLE);
		return lBtn;
	}
	
	/**
	 * @title  : 
	 * @location : com.oraking.android.cmm.view.TitleView.openRightBtn
	 * @writeDay : 2011. 9. 29. 오후 3:30:03
	 * @Todo  : TitleView 오른쪽 Button 보이도록 설정하는 Method
	 */
	public Button openRightBtn() {
		rBtn.setVisibility(View.VISIBLE);
		return rBtn;
	}
	
	/**
	 * @title  : 
	 * @location : com.oraking.android.cmm.view.TitleView.setBackgroundImage
	 * @writeDay : 2011. 9. 29. 오후 3:30:03
	 * @Todo  : TitleView 배경이미지를 설정하는 Method
	 */
	public void setBackgroundImage(int resid){
		titleTextView.setBackgroundResource(resid);
	}	
}
